<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>每日早报 - Electron 应用</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 
                         'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 900px;
            margin: 0 auto;
            background: white;
            border-radius: 15px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
            overflow: hidden;
        }

        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }

        .header h1 {
            font-size: 32px;
            margin-bottom: 10px;
            font-weight: 600;
        }

        .date {
            font-size: 16px;
            opacity: 0.9;
        }

        .refresh-btn {
            background: white;
            color: #667eea;
            border: none;
            padding: 10px 25px;
            border-radius: 25px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            margin-top: 15px;
            transition: all 0.3s;
        }

        .refresh-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }

        .refresh-btn:active {
            transform: translateY(0);
        }

        .refresh-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
        }

        .content {
            padding: 30px;
        }

        .loading {
            text-align: center;
            padding: 40px;
            color: #666;
            font-size: 16px;
        }

        .error {
            text-align: center;
            padding: 40px;
            color: #e74c3c;
            font-size: 16px;
        }

        .news-list {
            list-style: none;
        }

        .news-item {
            padding: 15px;
            margin-bottom: 10px;
            background: #f8f9fa;
            border-radius: 8px;
            border-left: 4px solid #667eea;
            transition: all 0.3s;
            line-height: 1.6;
        }

        .news-item:hover {
            background: #e9ecef;
            transform: translateX(5px);
        }

        .news-number {
            display: inline-block;
            width: 24px;
            height: 24px;
            background: #667eea;
            color: white;
            border-radius: 50%;
            text-align: center;
            line-height: 24px;
            font-size: 12px;
            font-weight: 600;
            margin-right: 10px;
        }

        .weiyu {
            margin-top: 30px;
            padding: 20px;
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            border-radius: 8px;
            font-style: italic;
            color: #333;
            text-align: center;
            line-height: 1.8;
        }

        .weiyu-label {
            font-weight: 600;
            color: #e74c3c;
            margin-right: 10px;
        }

        .footer {
            text-align: center;
            padding: 20px;
            color: #999;
            font-size: 12px;
            border-top: 1px solid #eee;
        }

        .spinner {
            border: 3px solid #f3f3f3;
            border-top: 3px solid #667eea;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>📰 每日早报</h1>
            <div class="date" id="date">加载中...</div>
            <button class="refresh-btn" id="refresh-btn" onclick="loadZaobao()">🔄 刷新</button>
        </div>
        
        <div class="content" id="content">
            <div class="loading">
                <div class="spinner"></div>
                <p style="margin-top: 20px;">正在获取最新早报...</p>
            </div>
        </div>
        
        <div class="footer">
            Powered by 坚果派 | 数据来源：ALAPI
        </div>
    </div>

    <script>
        // 加载早报数据
        async function loadZaobao() {
            const content = document.getElementById('content');
            const refreshBtn = document.getElementById('refresh-btn');
            
            // 显示加载状态
            content.innerHTML = `
                <div class="loading">
                    <div class="spinner"></div>
                    <p style="margin-top: 20px;">正在获取最新早报...</p>
                </div>
            `;
            
            refreshBtn.disabled = true;
            
            try {
                // 调用主进程获取数据
                const result = await window.electronAPI.fetchZaobao();
                
                if (result.code === 200 && result.data) {
                    const data = result.data;
                    
                    // 更新日期
                    document.getElementById('date').textContent = data.date;
                    
                    // 生成新闻列表
                    let newsHtml = '<ul class="news-list">';
                    if (data.news && data.news.length > 0) {
                        data.news.forEach((item, index) => {
                            newsHtml += `
                                <li class="news-item">
                                    <span class="news-number">${index + 1}</span>
                                    ${item}
                                </li>
                            `;
                        });
                    }
                    newsHtml += '</ul>';
                    
                    // 添加微语
                    if (data.weiyu) {
                        newsHtml += `
                            <div class="weiyu">
                                <span class="weiyu-label">💭 微语：</span>
                                ${data.weiyu.replace('【微语】', '')}
                            </div>
                        `;
                    }
                    
                    content.innerHTML = newsHtml;
                } else {
                    throw new Error(result.msg || '获取数据失败');
                }
            } catch (error) {
                content.innerHTML = `
                    <div class="error">
                        <p>❌ 获取早报失败</p>
                        <p style="margin-top: 10px; font-size: 14px;">${error.message}</p>
                    </div>
                `;
            } finally {
                refreshBtn.disabled = false;
            }
        }
        
        // 页面加载时自动获取数据
        window.addEventListener('DOMContentLoaded', () => {
            loadZaobao();
        });
    </script>
</body>
</html>